package servlet;

import bean.Result;
import biz.CartBiz;
import utils.Util;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.rmi.server.UID;

@WebServlet(name = "RemoveCartProductServlet", value = "/RemoveCartProductServlet.s")
public class RemoveCartProductServlet extends HttpServlet {
    private CartBiz biz = new CartBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Result result;
        try {
            String uid = String.valueOf(request.getSession().getAttribute("userid"));
            String product = request.getParameter("product");
            String amount = request.getParameter("amount");
            biz.remove(uid, product, amount);
            result = new Result(1, "删除成功!",null);
        } catch (Exception e) {
            e.printStackTrace();
            result = new Result(1,"删除失败!", null);
        }
        Util.WriteJson(result, response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
